<!doctype html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
</head>
<body>
<!--header start -->
{include file="headerimport"}
<!--header end-->


<table class="weui-table weui-border-tb" id="cusTable">
    <thead>
    <tr>
        <th  data-field="username" style="border-left:2px solid #fff">后缀名</th>
        <th>公司</th>
        <th>状态</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {volist name="data" id="vo"}
        <tr>
            <td data-field="" id="sub" style="border-left:2px solid #fff">{$vo.suffix}</td>
            <th>{$vo.companyname}</th>
            <th><a href="###" onclick="change(this)" data-id="{$vo.id}" statuid="{$vo.statuid}" suffix="{$vo.suffix}"><span>{$vo.statuid==1?'正常':'禁用'}</span></a>
            </th>
            <th>{$vo.creat_time}</th>
            <th>
                <a href="{:url('edit',array('id'=>$vo.id))}" id="edit" data-id="{$vo.id}"><span class="icon icon-115" title="编辑">编辑</span></a>
                <a href="###" id="delete" data-id="{$vo.id}" onclick="del(this)" suffix="{$vo.suffix}"><span class="icon icon-23"  title="删除" >删除</span></a>
            </th>
        </tr>
    {/volist}

    </tbody>
</table>


<div class="pages">{$page}</div>
<!--footer start -->
{include file="footer"}
<!--footer end-->
<script>
    //修改状态
    function change(_this){
        var uid = $(_this).attr('data-id');
        var statuid = $(_this).attr('statuid');
        var suffix = $(_this).attr('suffix');
        $.ajax({
            type:'post',
            url:"{:url('changeatatuid')}",
            data:{'id':uid,'statuid':statuid,'suffix':suffix},
            success:function(data){
                if(data.msg == '修改成功'){
                    if(data.statuid == 1){
                        $(_this).find('span').text('正常');
                        $(_this).attr('statuid',1);

                    }else{
                        $(_this).find('span').text('禁用');
                        $(_this).attr('statuid',0);

                    }
                }
            }
        })
    }

    //删除
    function del(_this){
        var uid = $(_this).attr('data-id');
        var suffix = $(_this).attr('suffix');
        $.ajax({
            type:'post',
            url:"{:url('Suffix/delete')}",
            data:{'id':uid,'suffix':suffix},
            success:function(data){
                console.log(data)
                switch(data){
                    case 1:
                        $(_this).parent().parent().remove();
                        break;
                    case 2:
                        alert('删除失败');
                        break;
                    case 3:
                        alert('用户不存在');
                        break;
                    case 4:
                        alert('请求格式不对');
                        break;
                }
            }
        })
    }
</script>
</body>
</html>